package cn.juforg.gobang;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.Toast;
import cn.juforg.gobang.player.AIFactory;
import cn.juforg.gobang.player.HumanPlayer;
/**
 * 
 * @author Juforg
 * 五子棋程序的入口
 */
public class GobangMain extends Activity {
	
	private static ChessBoard gameView ;
//	private static ChessBoardImpl cbi = new ChessBoardImpl();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gobang_view);
        Intent intent = getIntent();
        char gameMode = intent.getCharExtra("gameMode", '1');
        gameView = (ChessBoard) findViewById(R.id.gobang);
        gameView.setAty(this);
        //判断游戏模式
        if (gameMode==GobangStartAty.HUMAN2HUMAN_MODE) {
        	gameView.setPlayer2(new HumanPlayer(ChessBoard.PLAYER2FLAG));
        	ChessBoard.chssboddao.restart(gameView);
        	ChessBoard.chssboddao.setStatus(gameView, ChessBoard.RUNNING);
		}else if (gameMode == GobangStartAty.HUMAN2AI_MODE) {
			gameView.setPlayer2(AIFactory.getInstance(3));
			ChessBoard.chssboddao.restart(gameView);
			ChessBoard.chssboddao.setStatus(gameView, ChessBoard.RUNNING);
		}
        
        DisplayMetrics metric = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metric);
        System.out.println("metric.xdpi"+metric.xdpi+"|widthPixels:"+metric.widthPixels+"|density:"+metric.density+"|densityDpi:"+metric.densityDpi);
        switch (metric.widthPixels) {
		case 240:
			ChessBoard.chessSize = 16;
			Toast.makeText(GobangMain.this, "pix:240", Toast.LENGTH_SHORT).show();
			break;
		case 480:
			ChessBoard.chessSize = 32;
			Toast.makeText(GobangMain.this, "pix:480", Toast.LENGTH_SHORT).show();
			break;
		}
    }

	@Override
	protected void onDestroy() {
		System.out.println("GoabngMain onDestroy");
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		System.out.println("GoabngMain onPause");
//		this.finishFromChild(getParent());
		super.onPause();
	}

	@Override
	protected void onRestart() {
		System.out.println("GoabngMain onRestart");
		super.onRestart();
	}

	@Override
	protected void onResume() {
		System.out.println("GoabngMain onResume");
		super.onResume();
	}

	@Override
	protected void onStart() {
		System.out.println("GoabngMain onStart");
		super.onStart();
	}

	@Override
	protected void onStop() {
		System.out.println("GoabngMain onStop");
		super.onStop();
	}
    
    
}